package com.ruoyi.web.controller.marry;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.marry.domain.TUserGiftRecord;
import com.ruoyi.marry.service.ITUserGiftRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 礼物记录Controller
 *
 * @author user_marry
 * @date 2020-11-25
 */
@RestController
@RequestMapping("/marry/giftRecord")
public class TUserGiftRecordController extends BaseController {

    @Autowired
    private ITUserGiftRecordService tUserGiftRecordService;

    /**
     * 查询礼物记录列表
     */
    @PreAuthorize("@ss.hasPermi('marry:giftRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(TUserGiftRecord tUserGiftRecord) {
        startPage();
        List<TUserGiftRecord> list = tUserGiftRecordService.selectTUserGiftRecordList(tUserGiftRecord);
        return getDataTable(list);
    }

    /**
     * 查询用户赠送的所有礼物记录列表（用于弹幕展示）
     */
    @PreAuthorize("@ss.hasPermi('marry:giftRecord:listAll')")
    @GetMapping("/listAll")
    public TableDataInfo listAll(TUserGiftRecord tUserGiftRecord) {
        startPage();
        List<TUserGiftRecord> list = tUserGiftRecordService.getBarrage(tUserGiftRecord.getLoversId());
        return getDataTable(list);
    }

    /**
     * 导出礼物记录列表
     */
    @PreAuthorize("@ss.hasPermi('marry:giftRecord:export')")
    @Log(title = "礼物记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TUserGiftRecord tUserGiftRecord) {
        List<TUserGiftRecord> list = tUserGiftRecordService.selectTUserGiftRecordList(tUserGiftRecord);
        ExcelUtil<TUserGiftRecord> util = new ExcelUtil<TUserGiftRecord>(TUserGiftRecord.class);
        return util.exportExcel(list, "giftRecord");
    }

    /**
     * 根据编号获取详细信息
     */
    @PreAuthorize("@ss.hasPermi('marry:giftRecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(tUserGiftRecordService.selectTUserGiftRecordById(id));
    }

    /**
     * 新增保存礼物记录
     */
    @PreAuthorize("@ss.hasPermi('marry:giftRecord:add')")
    @Log(title = "礼物记录", businessType = BusinessType.INSERT)
    @PostMapping
    @RepeatSubmit
    public AjaxResult add(@RequestBody TUserGiftRecord tUserGiftRecord) {
        return toAjax(tUserGiftRecordService.insertTUserGiftRecord(tUserGiftRecord));
    }

    /**
     * 修改保存礼物记录
     */
    @PreAuthorize("@ss.hasPermi('marry:giftRecord:edit')")
    @Log(title = "礼物记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TUserGiftRecord tUserGiftRecord) {
        return toAjax(tUserGiftRecordService.updateTUserGiftRecord(tUserGiftRecord));
    }

    /**
     * 删除礼物记录
     */
    @PreAuthorize("@ss.hasPermi('marry:giftRecord:remove')")
    @Log(title = "礼物记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(tUserGiftRecordService.deleteTUserGiftRecordByIds(ids));
    }
}
